package cn.lizhangqu.kb.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.loopj.android.http.AsyncHttpResponseHandler;

import org.apache.http.Header;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import cn.lizhangqu.kb.R;
import cn.lizhangqu.kb.api.LgrgApi;
import cn.lizhangqu.kb.util.CommonUtil;
import cn.lizhangqu.kb.util.Toasts;

/**
 * Created by 柯尊诚 on 2015/11/5.
 * kzc
 */
public class LgrgActivity extends Activity{

    private TextView newsTv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news);
        init();

        getList();

    }

    private void init() {
        newsTv = (TextView) findViewById(R.id.tv_lgrg_news);
    }



    private void getList() {

        final ProgressDialog dialog = CommonUtil.getProcessDialog(this,"正在获取.......");
        dialog.show();
        LgrgApi.getJwNoticeList("column/20150911100000000016", new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                Document doc = Jsoup.parse(new String(responseBody));
                Elements elements = doc.select("ul#atArticles");
                Log.d("xxxid2", elements.get(0).childNodeSize()+"");

                for (int i = 0; i < 20; i++) {
                    Element element = elements.get(0).child(i);
                    Log.d("xxxid", element.childNodeSize() + "");

                    Log.d("xxxx", element.child(0).attr("href"));
                    Log.d("xxxx1", element.child(0).text() + i);
                    Log.d("xxxx2", element.child(1).text());
                }
//
                newsTv.setText(elements.toString());
                dialog.dismiss();
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                Toasts.makeText("请求失败！");
                dialog.dismiss();
            }
        });

    }


}
